#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

typedef long long ll;
ll qmod(ll a, ll n, ll mod)
{
	ll res = 1;
	while (n) {
		if (n & 1)
			res = (res * a) % mod;
		n >>= 1;
		a = (a * a) % mod;
	}
	return res % mod;
}

int main()
{
	int a, b, c, ans = 1;
	cin >> a >> b >> c;
	printf("%d^%d mod %d=%d", a, b, c, qmod(a, b, c));
	return 0;
}

//2^10 mod 9=7